package com.cumt.threeway.view.dialog;

import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.View.OnClickListener;
import android.view.ViewGroup;

import com.cumt.threeway.R;


public class ExitAppDialog extends DialogFragment implements OnClickListener{
	
	private Context mContext;

	public static ExitAppDialog newInstance(){
		ExitAppDialog exitAppDialog = new ExitAppDialog();
		return exitAppDialog;
	}
	
	@Override
	public void onAttach(Activity activity) {
		super.onAttach(activity);
		mContext = activity;
	}
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
		getDialog().getWindow().requestFeature(Window.FEATURE_NO_TITLE);
		getDialog().getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
		View view = inflater.inflate(R.layout.dialog_exit_app, null, false);
		initView(view);
		return view;
	}

	private void initView(View view) {
		view.findViewById(R.id.btn_confirm).setOnClickListener(this);
		view.findViewById(R.id.btn_cancel).setOnClickListener(this);
	}

	@Override
	public void onClick(View v) {
		switch (v.getId()) {
		case R.id.btn_confirm:
			((Activity) mContext).finish();
			break;
		case R.id.btn_cancel:
			dismissDialog();
			break;

		default:
			break;
		}
	}
	
	private void dismissDialog() {
		if (getDialog().isShowing()) {
			this.dismiss();
		}
	}
}
